package com.boot.security.server.common;

import java.io.Serializable;
import java.util.List;

public class PaginationResult<T> implements Serializable {
    private static final long serialVersionUID = 1L;
    public int code;
    private String message;
    private List<T> data;
    private int total;

    public List<T> getData() {
        return data;
    }

    public void setData(List<T> data) {
        this.data = data;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public static <T> PaginationResult<T> success(List<T> data, int total) {
        PaginationResult<T> paginationResult = new PaginationResult<>();
        paginationResult.setCode(ErrorCode.OK.getCode());
        paginationResult.setMessage(ErrorCode.OK.getMessage());
        paginationResult.setData(data);
        paginationResult.setTotal(total);
        return paginationResult;
    }
    public static <T> PaginationResult<T> error(String msg) {
        PaginationResult<T> paginationResult = new PaginationResult<>();
        paginationResult.setCode(ErrorCode.FAIL.getCode());
        paginationResult.setMessage(msg);
        return paginationResult;
    }
}
